Skip to content

remove _ in BigDecimal() in first-look-at-types.md #2843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jinfei1125
Copy link

The _ literal will result in following error:
:6: error: Invalid literal number
val a = BigDecimal(123_456.789)

The `_` literal will result in following error:
 <console>:6: error: Invalid literal number
       val a = BigDecimal(123_456.789)
@Philippus
Copy link
Member

I think underscores in numeric literals these were introduced in Scala 2.13. Perhaps you are using Scala 2.12?

@jinfei1125
Copy link
Author

I think underscores in numeric literals these were introduced in Scala 2.13. Perhaps you are using Scala 2.12?

@Philippus Yep you're right! I'm in scala 2.12 now. Is _ commonly used? I can't easily find the official documentation about it by googling...

@jinfei1125
Copy link
Author

Ah, it's a separator for readability purposes. Although, for the spirit of simplicity for official documentation and support multiple versions of scala, I suggest we remove _. But if you think it's okay to leave a version-specific example there, I can close this pull request. @Philippus

@SethTisue SethTisue closed this Jul 6, 2023
@SethTisue SethTisue reopened this Jul 6, 2023
@SethTisue
Copy link
Member

SethTisue commented Jul 6, 2023

Hmm... I reopened thinking the problem was fixable by having separate Scala 2 and 3 versions of the code sample, but then I realized that would give the incorrect impression that the Scala 3 version wouldn't compile on 2.13.

Thank you for the pull request. I think it's better we leave this alone. If you want to learn Scala 2.12, the best thing to do would be to get a Scala 2.12 book, otherwise you'll be bedeviled by all sorts of small incompatibilities like this.

@SethTisue SethTisue closed this Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants